import  dayjs from 'dayjs'
import  Request from './request'
const tool = {
  toOtherApp (appId, path) {
    uni.navigateToMiniProgram({
      appId: appId,
      path: path,
      success (res) {
        // 打开成功
        Request.post('/exchange/app_log',
          { 'app_id': appId, 'type': 'out' })
      },
    })
  },
  timeToString(time,format){
    if(!time)
      return '';

    if(!format){
      format = 'YYYY-MM-DD'
    }

    // console.log(time.length);
    // if(time>time.length>18){
    //   time=time/1000;
    // }
    let theTime = dayjs(time).valueOf();
    let now = new Date().getTime();

    console.log(now);
    console.log(time);
    console.log(theTime,'theTime');
    if( (now- theTime) < 3600){
      return '刚刚';
    }else if( (now- theTime) < 3600*12){

      if(theTime<15729400450){
        theTime = theTime*1000;
      }
      return '今天 '+ dayjs(theTime).format('HH:mm')
    }else{
      if(theTime<15729400450){
        theTime = theTime*1000;
      }
      return dayjs(theTime).format(format)
    }
  },
  showNumber(number){
    if (number > 10000) {
      return (number/1000).toFixed(1)+'w';
    } else {
      return number;
    }
  },
}
export default tool
